/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.irssproject.app.entitats;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;

/**
 *
 * @author adria
 */
@Entity
@Table(name = "perfils_lectura")
public class ReadingProfile implements Serializable {

    private static final long serialVersionUID = 1L;
    
    private Long id;
    private Date addedDate;
    private User user;
    private Feed feed;
    private Item item;
    private Topic topic;
    private Integer relevance;

    public ReadingProfile() {
    }
    
    public ReadingProfile(Long id){
        this.id = id;
    }
    
    public ReadingProfile(User user, Feed feed, Item item, Topic topic){
        this.user = user;
        this.feed = feed;
        this.item = item;
        this.topic = topic;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idperfil")
    public Long getId() {
        return id;
    }

    public void setId(Long idperfil) {
        this.id = idperfil;
    }

    @Basic(optional = false)
    @Column(name = "dataafegit", insertable = false)
    @Temporal(value = TemporalType.TIMESTAMP)
    public Date getAddedDate() {
        return addedDate;
    }

    public void setAddedDate(Date dataafegit) {
        this.addedDate = dataafegit;
    }

    @JoinColumn(name = "idusuari", referencedColumnName = "idusuari")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    public User getUser() {
        return user;
    }

    public void setUser(User usuari) {
        this.user = usuari;
    }

    @JoinColumn(name = "idfeed", referencedColumnName = "idfeed")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    public Feed getFeed() {
        return feed;
    }

    public void setFeed(Feed feed) {
        this.feed = feed;
    }

    @JoinColumn(name = "iditem", referencedColumnName = "iditem")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    public Item getItem() {
        return item;
    }

    public void setItem(Item item) {
        this.item = item;
    }

    @JoinColumn(name = "idconcepte", referencedColumnName = "id")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    public Topic getTopic() {
        return topic;
    }

    public void setTopic(Topic concepte) {
        this.topic = concepte;
    }

    @Basic(optional = false)
    @Column(name = "frequencia")
    public Integer getRelevance() {
        return relevance;
    }

    public void setRelevance(Integer frequencia) {
        this.relevance = frequencia;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ReadingProfile)) {
            return false;
        }
        ReadingProfile other = (ReadingProfile) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "[ user: " + user.getLogin() + ", feed: " + feed.getTitol() + ", item: " + item.getTitle() + ", concept: " + topic.getValor() + " ]";
    }
}
